package com.ruizhong.centercontroll.handler;



import com.ruizhong.centercontroll.util.Result;
import com.ruizhong.centercontroll.util.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RestControllerAdvice
@Slf4j
public class BaseExceptionHandler {


    @ExceptionHandler(value = RuntimeException.class)
    public Result runtimeError(HttpServletRequest request, HttpServletResponse response, RuntimeException exception){
        System.out.println(exception.getMessage());
        if (exception.getMessage().equals("请先登录")){
            return new Result(401,"请先进行登录",null);
        }else if (exception.getMessage().equals("需要输入密码以执行本次操作")){
            return new Result(402,"需要输入密码以执行本次操作",null);
        }
        return new Result(ResultCode.error,exception.getMessage(),null);
    }

}
